package com.sky.controller.user;


import com.sky.constant.StatusConstant;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Setmeal;
import com.sky.entity.SetmealDish;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.DishVO;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
@ApiModel("套餐相关接口")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;


    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getById(@PathVariable Long id){
        SetmealVO setmealVo = setmealService.getById(id);
        return Result.success(setmealVo);
    }

    @GetMapping("/list")
    @ApiOperation("根据套餐分类Id查询关联菜品")
    @Cacheable(cacheNames = "userSetmealCache",key = "'setmeal_'+#categoryId")
    public Result<List<Setmeal>> list(Long categoryId){
        Setmeal setmeal = Setmeal.builder()
                .status(StatusConstant.ENABLE)
                .categoryId(categoryId)
                        .build();
       List<Setmeal> setmeals = setmealService.list(setmeal);
       return Result.success(setmeals);
    }
    @GetMapping("/dish/{id}")
    @ApiOperation("根据套餐id，查询关联菜品")
    public Result<List<DishItemVO>> getDishsBySetmealId(@PathVariable Long id){
       List<DishItemVO> dishItemVOS = setmealService.getDishsWithDetailBySetmealId(id);
       return Result.success(dishItemVOS);
    }

}
